package main

import (
	"flag"
	"log"
	"os"

	"upload-to-obs/internal"
)

var endPoint = flag.String("endpoint", os.Getenv("PLUGIN_ENDPOINT"), "upload endpoint")
var ak = flag.String("ak", os.Getenv("PLUGIN_AK"), "Access Key Id")
var sk = flag.String("sk", os.Getenv("PLUGIN_SK"), "Secret Access Key")
var bucket = flag.String("bucket", os.Getenv("PLUGIN_BUCKET"), "bucket name")
var key = flag.String("key", os.Getenv("PLUGIN_KEY"), "target key")
var sourceFile = flag.String("source_file", os.Getenv("PLUGIN_SOURCE_FILE"), "source file")

func init() {
	log.SetFlags(log.Lshortfile | log.Ldate)
	df := flag.Usage
	flag.Usage = func() {
		df()
	}
}

func main() {
	flag.Parse()

	err := internal.Upload(*endPoint, *ak, *sk, *bucket, *key, *sourceFile)
	if err != nil {
		log.Printf("upload file to obs fail, err: %+v", err)
	}
}
